/*
 * These files are distributed under the terms of the GNU GPLv2, the GNU General
 * Public version 2. See LICENSE.txt
 */
package fileCommodore.plugin.dos_shell;

import java.awt.*;
import java.awt.event.*;
import java.io.*;

import javax.swing.*;

import de.mud.terminal.*;
import fileCommodore.plugin.*;
import fileCommodore.terminal.*;

/**
 * @author nado18@gmail.com, on Jul 26, 2007
 */
public class DosShellPlugin extends Plugin
{
	/*
	 * (non-Javadoc)
	 * 
	 * @see plugin.Plugin#handle(java.awt.event.KeyEvent)
	 */
	@Override
	public void handle( KeyEvent ev )
	{
		if (KeyEvent.VK_F10 == ev.getKeyCode()
				|| ( KeyEvent.VK_DIVIDE == ev.getKeyCode() && KeyEvent.KEY_LOCATION_NUMPAD == ev.getKeyLocation() ))
		{
			try
			{
				File currentDir =
						new File(
								getActiveSelection().getCurrent().getFileObject().getName().getPath() );
				
				Terminal terminal = new Terminal();
				Font font = new Font( "Courier New", Font.PLAIN, 16 );
				SwingTerminal st = new SwingTerminal( terminal, font );
				st.setScrollbar( new JScrollBar() );
				
				Process p = launchTerminal( currentDir );
				
				terminal.setProcess( p );
			}
			catch (IOException e)
			{
				report( "Could not open DOS shell.", e );
			}
		}
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see plugin.Plugin#activeSelectionChanged()
	 */
	@Override
	public void activeSelectionChanged()
	{
		// TODO Auto-generated method stub
		
	}
	
	/*
	 * (non-Javadoc)
	 * 
	 * @see plugin.Plugin#inactiveSelectionChanged()
	 */
	@Override
	public void inactiveSelectionChanged()
	{
		// TODO Auto-generated method stub
		
	}
}
